﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Engine.Material.Shader;
using Microsoft.Xna.Framework.Graphics;
using XNAnimation.Effects;
using Microsoft.Xna.Framework;
using Engine.Cameras;
using Engine.Modelo.Animation;

namespace Engine.Material.Shader
{
    public class SimpleAnimationShader : IShader
    {

        public SimpleAnimationShader(IAnimatedController ac)
        {
            this.ac = ac;
        }
        private IAnimatedController ac;
        private ICamera cam;
        private Matrix WorldMatrix;
        
        

        public override void  Update(Engine.SceneControl.IObject ent, Engine.Cameras.ICamera cam, IList<Engine.Light.ILight> lights)
        {
            
 	        this.cam = cam;
            this.WorldMatrix = ent.getWorldMatrix();
            
        }


        public override void Draw(Engine.Modelo.IModelo modelo)
        {
            Model model = modelo.getModel(0);

            foreach (ModelMesh modelMesh in model.Meshes)
            {
                foreach (ModelMeshPart meshPart in modelMesh.MeshParts)
                {
                    SkinnedModelBasicEffect basicEffect = (SkinnedModelBasicEffect) meshPart.Effect;

                    basicEffect.World = WorldMatrix;
                    basicEffect.Bones = ac.GetBoneTransformations();
                    basicEffect.View = cam.View;
                    basicEffect.Projection = cam.Projection;

                    // OPTIONAL - Configure material
                    basicEffect.Material.DiffuseColor = new Vector3(0.8f);
                    basicEffect.Material.SpecularColor = new Vector3(0.3f);
                    basicEffect.Material.SpecularPower = 8;
                    
                    //basicEffect.NormalMapEnabled = enableNormalTexture;

                    //basicEffect.SpecularMapEnabled = enableSpecularTexture;
                    //basicEffect.SpecularMap = specularTexture;
                    //if (enableSpecularTexture)
                    //    basicEffect.Material.SpecularColor = new Vector3(1.0f);

                    // OPTIONAL - Configure lights
                    basicEffect.AmbientLightColor = new Vector3(0.1f);
                    basicEffect.LightEnabled = true;
                    basicEffect.EnabledLights = EnabledLights.One;
                    basicEffect.PointLights[0].Color = Vector3.One;
                    basicEffect.PointLights[0].Position = new Vector3(100, 100, 100);
                }

                
                modelMesh.Draw();
            }

                  
        
            
        }
    }
}
